// BatchSmsDialog.cpp : implementation of the CBatchSmsDialog class
//
/////////////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#ifdef WIN32_PLATFORM_PSPC
#include "resourceppc.h"
#else
#include "resourcesp.h"
#endif

#include "aboutdlg.h"
#include "BatchSmsDialog.h"
#include "GroupsDlg.h"
#include "DraftsDlg.h"
#include "BatchesDlg.h"
#include "DraftInfoDlg.h"
#include "MembersDlg.h"
#include "SendStatusDlg.h"
#include "SendInfoDlg.h"
#include "GroupsDb.h"
#include "DraftsDb.h"

BOOL CBatchSmsDialog::PreTranslateMessage(MSG* pMsg)
{
    return CWindow::IsDialogMessage(pMsg);
}

bool CBatchSmsDialog::AppHibernate( bool bHibernate)
{
    // Insert your code here or delete member if not relevant
    return bHibernate;
}

bool CBatchSmsDialog::AppNewInstance( LPCTSTR lpstrCmdLine)
{
    // Insert your code here or delete member if not relevant
    return false;
}

void CBatchSmsDialog::AppSave()
{
    CAppInfo info;
    // Insert your code here or delete member if not relevant
}

#ifdef WIN32_PLATFORM_WFSP
void CBatchSmsDialog::AppBackKey() 
{
    StdCloseDialog(IDCANCEL);
}
#endif

BOOL CBatchSmsDialog::OnIdle()
{
    return FALSE;
}

LRESULT CBatchSmsDialog::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
{
    HWND hMenuBar = CreateMenuBar(IDM_MAINDLG);
    UIAddToolBar(hMenuBar);
    UIAddChildWindowContainer(m_hWnd);

    // register object for message filtering and idle updates
    CMessageLoop* pLoop = _Module.GetMessageLoop();
    ATLASSERT(pLoop != NULL);
    pLoop->AddMessageFilter(this);
    pLoop->AddIdleHandler(this);

    BOOL Ret = m_ImageList.Create(32, 32, ILC_COLORDDB | ILC_MASK, 4, 0);
    ATLASSERT(Ret == TRUE);

    CIcon icon;
    icon.LoadIcon(IDI_BATCHES);
    int Result = m_ImageList.AddIcon(icon);
    ATLASSERT(Result != -1);
    icon.DestroyIcon();

    icon.LoadIcon(IDI_GROUPS);
    Result = m_ImageList.AddIcon(icon);
    ATLASSERT(Result != -1);
    icon.DestroyIcon();

    icon.LoadIcon(IDI_DRAFTS);
    Result = m_ImageList.AddIcon(icon);
    ATLASSERT(Result != -1);
    icon.DestroyIcon();

    m_List.Attach(GetDlgItem(IDC_LIST));
    m_List.SetExtendedListViewStyle(LVS_EX_FULLROWSELECT);
    m_List.SetImageList(m_ImageList, LVSIL_SMALL);

    CRect r;
    m_List.GetClientRect(&r);
    m_List.InsertColumn(0, NULL, LVCFMT_LEFT, r.Width());

    CString s;
    s.LoadString(IDS_BATCHES);
    m_List.AddItem(ITEM_BATCHES, 0, s, ITEM_BATCHES);

    s.LoadString(IDS_GROUPS);
    m_List.AddItem(ITEM_GROUPS, 0, s, ITEM_GROUPS);

    s.LoadString(IDS_DRAFTS);
    m_List.AddItem(ITEM_DRAFTS, 0, s, ITEM_DRAFTS);

    m_List.SelectItem(ITEM_BATCHES);
    m_List.SetFocus();

    return bHandled = FALSE;
}

LRESULT CBatchSmsDialog::OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
{
    m_List.Detach();
    return bHandled = FALSE;
}

#ifdef WIN32_PLATFORM_PSPC
LRESULT CBatchSmsDialog::OnSettingChange(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
    // prevent resizing on SIP change
    return 0;
}
#endif

LRESULT CBatchSmsDialog::OnMenuExit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
    StdCloseDialog(IDOK);
    return 0;
}

LRESULT CBatchSmsDialog::OnMenuAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
    CAboutDlg dlg;
    dlg.DoModal();
    return 0;
}

LRESULT CBatchSmsDialog::OnListClick(int idCtrl, LPNMHDR pnmh, BOOL& /*bHandled*/)
{
    OnItem(((NMLISTVIEW *)pnmh)->iItem);
    return 0;
}

LRESULT CBatchSmsDialog::OnListReturn(int idCtrl, LPNMHDR pnmh, BOOL& /*bHandled*/)
{
    OnItem(((NMLISTVIEW *)pnmh)->iItem);
    return 0;
}

void CBatchSmsDialog::OnItem(int ItemId)
{
    switch (ItemId)
    {
    case ITEM_BATCHES:
        {
            CSendStatusDlg dlg;
            dlg.DoModal(m_hWnd);
        }
        break;
    case ITEM_GROUPS:
        {
            CGroupsDlg dlg;
            dlg.DoModal(m_hWnd);
        }
        break;
    case ITEM_DRAFTS:
        {
            CDraftsDlg dlg;
            dlg.DoModal(m_hWnd);
        }
        break;
    case ITEM_HISTORY:
        break;
    }
}

LRESULT CBatchSmsDialog::OnSize(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
{
    CRect r;
    m_List.GetClientRect(&r);
    m_List.SetColumnWidth(0, r.Width());
    return bHandled = FALSE;
}
